package com.arellomobile.android.push.utils.notification;

import android.app.Notification;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import com.arellomobile.android.push.preference.SoundType;
import com.arellomobile.android.push.preference.VibrateType;

public abstract class BaseNotificationFactory
{
  private Context mContext;
  private Bundle mData;
  private String mHeader;
  private String mMessage;
  private Notification mNotification;
  private SoundType mSoundType;
  private VibrateType mVibrateType;

  public BaseNotificationFactory(Context paramContext, Bundle paramBundle, String paramString1, String paramString2, SoundType paramSoundType, VibrateType paramVibrateType)
  {
    this.mContext = paramContext;
    this.mData = paramBundle;
    this.mHeader = paramString1;
    this.mMessage = paramString2;
    this.mSoundType = paramSoundType;
    this.mVibrateType = paramVibrateType;
  }

  private static void addPushNotificationSound(Context paramContext, Notification paramNotification, String paramString)
  {
    if ((paramString != null) && (paramString.length() != 0))
    {
      int i = paramContext.getResources().getIdentifier(paramString, "raw", paramContext.getPackageName());
      if (i != 0)
      {
        paramNotification.sound = Uri.parse("android.resource://" + paramContext.getPackageName() + "/" + i);
        return;
      }
    }
    paramNotification.defaults = (0x1 | paramNotification.defaults);
  }

  private static boolean phoneHaveVibratePermission(Context paramContext)
  {
    PackageManager localPackageManager = paramContext.getPackageManager();
    try
    {
      int i = localPackageManager.checkPermission("android.permission.VIBRATE", paramContext.getPackageName());
      if (i == 0)
        return true;
    }
    catch (Exception localException)
    {
      Log.e("PushWoosh", "error in checking vibrate permission", localException);
    }
    return false;
  }

  public void addCancel()
  {
    Notification localNotification = this.mNotification;
    localNotification.flags = (0x10 | localNotification.flags);
  }

  public void addLED(boolean paramBoolean)
  {
    if (!paramBoolean)
      return;
    this.mNotification.ledARGB = -1;
    this.mNotification.flags = 1;
    this.mNotification.ledOnMS = 100;
    this.mNotification.ledOffMS = 1000;
  }

  public void addSoundAndVibrate()
  {
    String str = (String)this.mData.get("s");
    AudioManager localAudioManager = (AudioManager)this.mContext.getSystemService("audio");
    if ((this.mSoundType == SoundType.ALWAYS) || ((localAudioManager.getRingerMode() == 2) && (this.mSoundType == SoundType.DEFAULT_MODE)))
      addPushNotificationSound(this.mContext, this.mNotification, str);
    if (((this.mVibrateType == VibrateType.ALWAYS) || ((localAudioManager.getRingerMode() == 1) && (this.mVibrateType == VibrateType.DEFAULT_MODE))) && (phoneHaveVibratePermission(this.mContext)))
    {
      Notification localNotification = this.mNotification;
      localNotification.defaults = (0x2 | localNotification.defaults);
    }
  }

  public void generateNotification()
  {
    int i = getContext().getResources().getIdentifier("new_push_message", "string", getContext().getPackageName());
    if (i != 0)
    {
      String str = getContext().getString(i);
      this.mNotification = generateNotificationInner(getContext(), getData(), this.mHeader, this.mMessage, str);
      return;
    }
    this.mNotification = generateNotificationInner(getContext(), getData(), this.mHeader, this.mMessage, this.mMessage);
  }

  abstract Notification generateNotificationInner(Context paramContext, Bundle paramBundle, String paramString1, String paramString2, String paramString3);

  protected Context getContext()
  {
    return this.mContext;
  }

  protected Bundle getData()
  {
    return this.mData;
  }

  public Notification getNotification()
  {
    return this.mNotification;
  }

  protected SoundType getSoundType()
  {
    return this.mSoundType;
  }

  protected VibrateType getVibrateType()
  {
    return this.mVibrateType;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.arellomobile.android.push.utils.notification.BaseNotificationFactory
 * JD-Core Version:    0.6.2
 */